package com.foreverwin.mes.meapi.service.impl;

import com.foreverwin.mes.common.constants.HandleBOConstants;
import com.foreverwin.mes.core.base.FrontPage;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.foreverwin.mes.meapi.model.CustomFields;
import com.foreverwin.mes.meapi.mapper.CustomFieldsMapper;
import com.foreverwin.mes.meapi.service.CustomFieldsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.catalina.util.CustomObjectInputStream;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ervin Chen
 * @since 2020-02-04
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CustomFieldsServiceImpl extends ServiceImpl<CustomFieldsMapper, CustomFields> implements CustomFieldsService {


    @Autowired
    private CustomFieldsMapper customFieldsMapper;

    @Override
    public Page<CustomFields> selectPage(FrontPage<CustomFields> frontPage, CustomFields customFields) {
        EntityWrapper<CustomFields> queryWrapper = new EntityWrapper<>();
        queryWrapper.setEntity(customFields);
        return super.selectPage(frontPage.getPagePlus(), queryWrapper);
    }

    @Override
    public List<CustomFields> selectList(CustomFields customFields) {
        EntityWrapper<CustomFields> queryWrapper = new EntityWrapper<>();
        queryWrapper.setEntity(customFields);
        return super.selectList(queryWrapper);
    }

    @Override
    public CustomFields getAttributeValue(String handle, String attribute) {
        List<CustomFields> customFieldsList = this.selectList(new EntityWrapper<CustomFields>()
                .eq(CustomFields.HANDLE, handle)
                .eq(CustomFields.ATTRIBUTE, attribute));
        return customFieldsList != null && customFieldsList.size() > 0 ? customFieldsList.get(0) : null;
    }

    @Override
    public List<CustomFields> listByHandle(String handle) {
        return this.selectList(new EntityWrapper<CustomFields>().eq(CustomFields.HANDLE, handle));
    }
}